import constents from "../common/constents.js";
import ajaxUlit from "./ajaxUlit.js";

const requestUtil = (url,method,param)=>{
	const promise = new Promise((resolve,reject)=>{
		const ajax = new ajaxUlit(
						url,
						{
							method:method,
							params:param,
							success:(response)=>{
								const jsonAes = JSON.parse(response);
								if(jsonAes.code == 1){
									resolve(jsonAes.data);
								}else if(jsonAes.code == 0){
									reject(`错误描述：${jsonAes.msg}`);
								}else{
									
								}
							},
							httpCodeErr:(status)=>{
								const httpConfig = constents.HTTP_CONFIG.httpCode;
								for (let val of httpConfig) {
									// console.log(val);
									if((status>=val.minCode)&&status<=val.maxCode){
										reject(`错误码：${status}--${val.desc}`);
									}
								}
							},
							error:()=>{
								reject("请求失败");
							},
							timeout:()=>{
								reject("请求超时");
							},
							abort:()=>{
								reject("请求被终止");
							},
						}
					)
						
	})
	return promise;
}
export default requestUtil;